#include <bits/stdc++.h>
#ifndef DEBUG
#define debug
#endif
using namespace std;
using i64 = int64_t;

void solve() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (auto &x : a) cin >> x;
  for (auto &x : b) cin >> x;
  int index = 0;
  stack<int> st;
  for (auto x : a) {
    st.push(x);
    while (!st.empty() && st.top() == b[index]) {
      st.pop();
      index ++;
    }
  }
  cout << (index == n ? "Yes" : "No") << endl;
}
int main() {
  cin.tie(0)->sync_with_stdio(0);
  int T = 1;
  cin >> T;
  for (int cas = 1; cas <= T; cas ++) {
    solve();
  }
}